<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>websocket测试</title>
</head>
<body>
    <h2>websocket接收测试</h2>
    <script>
        var url = window.location.host
        var port = window.location.port
        var ws = new WebSocket('ws://' + url)
        // 连接成功
        ws.onopen = function(evt){
            console.log("connetced Suss")
            ws.send("ok i connected")
        }
        // 关闭连接
        ws.onclose = function (evt) {
            console.log("Bye")
        }
        ws.onmessage = function (evt) {
            console.log('recved :' + evt.data);
        }
    </script>
</body>
</html>